package com.yybray.spliterator;

/**
 * Created by Bray on 2017/6/14.
 */
public class SimpleWordCounter {
    public static int countWords(String s) {
        int counter = 0;
        boolean lastSpace = true;
        for (char c : s.toCharArray()) {
            if (Character.isWhitespace(c)) {
                lastSpace = true;
            } else {
                //上一个字符是空格单词数量+1
                if (lastSpace) counter++;
                lastSpace = false;
            }
        }
        return counter;
    }
}
